package com.example.dragdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.maps.MapView;

public class MainActivity extends AppCompatActivity {
    private MapView mMapView = null;
    private DragLayout dlContainer;
    private View vTitlebg;
    private TextView tvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取地图控件引用
        mMapView = (MapView) findViewById(R.id.map);
        //在activity执行onCreate时执行mMapView.onCreate(savedInstanceState)，创建地图
        mMapView.onCreate(savedInstanceState);
        dlContainer = (DragLayout) findViewById(R.id.dl_container);
        vTitlebg = (View) findViewById(R.id.v_titlebg);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        dlContainer.setScrollProgressListener(new DragLayout.ScrollProgressListener() {
            @Override
            public void onScroll(int maxOffset, int scrollVal) {
                //计算出当前滑动距离与最大展开距离的百分比
                float percent = scrollVal / 1.0f / maxOffset;
                Log.e("滑动百分比",percent + "");
                //当我们滑到底的时候让标题和标题栏背景变为透明
                vTitlebg.setAlpha(1 - percent);
                tvTitle.setAlpha(1 - percent);
            }
        });
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        mMapView.onDestroy();
    }
    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mMapView.onResume();
    }
    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mMapView.onPause();
    }
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mMapView.onSaveInstanceState(outState);
    }
}